﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PRDP.Tools;
using System.Collections.Generic;

public partial class searchmore : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        laSearchMoreHTML.Text = generateSearchMoreHTML();
    }

    public string generateSearchMoreHTML()
    {
        List<Hashtable> rows = MyDBHandler.getAllList("select ID,CnName,Description from Type where PID=-1");
        int count = 0;
        string result = string.Empty;
        foreach (Hashtable row in rows)
        {
            string subTypeStr = getSubTypeName(row["ID"].ToString());
            string linkStr = "<A class=a15 href=\"#\" onclick=\"linkMore('" + row["ID"].ToString() + "')\"><B><U>" + row["CnName"].ToString() + "</U></B></A>" + (string.IsNullOrEmpty(subTypeStr) ? "" : "&nbsp;&nbsp;(" + subTypeStr + ")") + "\r\n";
            if (count++ % 2 == 0)
            {
                result += "<tr><td width=\"8%\" height=50>&nbsp; </td>";
                result += "<td align=left width=\"48%\">";
                result += linkStr;
                result += "<BR>" + row["Description"] + " </td>\r\n";
            }
            else
            {
                result += "<td align=left width=\"44%\">";
                result += linkStr;
                result += "<BR>" + row["Description"] + " </td>\r\n";
                result += "</tr>";
            }
        }
        return result;
    }

    public string getSubTypeName(string typeID)
    {
        string result = string.Empty;
        List<Hashtable> rows = MyDBHandler.getAllList("select CnName from Type where PID=" + typeID);
        foreach (Hashtable row in rows)
        {
            result += row["CnName"].ToString() + ",";
        }
        return result.Trim(",".ToCharArray());
    }
}
